Imports System.Windows.Forms

Public Class OptionForm

    Private _options As WindowsLive.Writer.Api.IProperties
    Public ReadOnly Property Options() As WindowsLive.Writer.Api.IProperties
        Get
            Return _options
        End Get
    End Property

    Public Sub New(ByVal options As WindowsLive.Writer.Api.IProperties)
        InitializeComponent()

        Try
            _options = Options

            CheckNoGutter.Checked = _options.GetNoGutter
            CheckNoControls.Checked = _options.GetNoControls
            CheckCollapse.Checked = _options.GetCollapse
            CheckFirstLine.Checked = _options.GetFirstLine
            CheckShowColumns.Checked = _options.GetShowColumns
            NumericUpDownLineValue.Value = _options.GetLineValue

            ' language
            ListLanguage.Items.AddRange(PluginSetting.Languages.ToArray)
            Try
                ListLanguage.SelectedItem = (From l In PluginSetting.Languages Where options.GetLanguage = l.ClassName).Single
            Catch ex As InvalidOperationException
                options.SetLanguage(PluginSetting.Languages.First.ClassName)
                ListLanguage.SelectedIndex = 0
            End Try

            ' Editor options
            ListInsertedActions.SelectedIndex = _options.GetInsertedAction
            ListEditedActions.SelectedIndex = _options.GetEditedAction
            NumericUpDownTabSize.Value = _options.GetTabSize

            '' inserting type of tag
            '' (textarea is not supported)
            'ListTag.Items.Clear()
            'ListTag.Items.AddRange(New String() {"pre", "textarea"})
            'If _options.GetString("tag", "pre").Equals("pre") Then
            '    ListTag.SelectedIndex = 0
            'Else
            '    ListTag.SelectedIndex = 1
            'End If

        Catch ex As Exception
#If DEBUG Then
            MessageBox.Show(ex.ToString)
#End If
        End Try
    End Sub


    Private Sub ButtonOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOk.Click

        With _options
            .SetNoGutter(CheckNoGutter.Checked)
            .SetNoControls(CheckNoControls.Checked)
            .SetCollapse(CheckCollapse.Checked)
            .SetFirstLine(CheckFirstLine.Checked)
            .SetShowColumns(CheckShowColumns.Checked)
            .SetLineValue(NumericUpDownLineValue.Value)

            .SetLanguage(DirectCast(ListLanguage.SelectedItem, PluginSetting.LanguageItem).ClassName)

            Try
                .SetInsertedAction(CType(ListInsertedActions.SelectedIndex, EditorActions))
                .SetEditedAction(CType(ListEditedActions.SelectedIndex, EditorActions))
                .SetTabSize(CInt(NumericUpDownTabSize.Value))
            Catch
                ' Ignore
            End Try

        End With

        Me.DialogResult = Windows.Forms.DialogResult.OK
    End Sub


    Private Sub CheckFirstLine_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckFirstLine.CheckedChanged
        NumericUpDownLineValue.Enabled = CheckFirstLine.Checked
    End Sub

End Class